﻿namespace MovieTicket.WebApi.BBL
{
    using System.Collections.Generic;
    using System.Linq;

    using MovieTicket.WebApi.BBL.BusinessObjects;

    /// <summary>
    /// Class MovieTicketBBL
    /// </summary>
    public class MovieTicketsBLL
    {
        #region Public Methods and Operators

        /// <summary>
        /// Adds the edit user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>System.Int32.</returns>
        public static int AddEditUser(UserBO user)
        {
            return MovieRepository.AddEditUser(user);
        }

        /// <summary>
        /// Gets the logged in user details.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <returns>UserBO.</returns>
        public static UserBO GetLoggedInUserDetails(string userName)
        {
            return MovieRepository.GetUserDetails(userName);
        }

        /// <summary>
        /// Gets the movie list.
        /// </summary>
        /// <param name="listType">Type of the list.</param>
        /// <returns>List{MovieBO}.</returns>
        public static List<MovieBO> GetMovieList(int listType)
        {
            var moviesMasterList = MovieRepository.GetMoviesMasterList();

            switch (listType)
            {
                    // return now playing movies
                case 0:
                    {
                        return moviesMasterList.Where(m => m.IsNowPlaying).ToList();
                    }

                    // return coming soon movies
                case 1:
                    {
                        return moviesMasterList.Where(m => !m.IsNowPlaying).ToList();
                    }

                    // return all the movies sorted by name
                default:
                    {
                        return moviesMasterList.OrderBy(x => x.Name).ToList();
                    }
            }
        }

        /// <summary>
        /// Gets the movies.
        /// </summary>
        /// <param name="searchKeyword">The search keyword.</param>
        /// <returns>List{MovieBO}.</returns>
        public static List<MovieBO> GetMovies(string searchKeyword)
        {
            return MovieRepository.GetMovies(searchKeyword);
        }

        /// <summary>
        /// Gets the theater list for movie.
        /// </summary>
        /// <param name="movieId">The movie id.</param>
        /// <returns>List{TheaterBO}.</returns>
        public static List<TheaterBO> GetTheaterListForMovie(int movieId)
        {
            // for any movie, return all the theatres 
            return MovieRepository.GetTheatresMasterList();
        }

        /// <summary>
        /// Gets the theaters.
        /// </summary>
        /// <param name="searchtheater">The searchtheater.</param>
        /// <returns>List{TheaterBO}.</returns>
        public static List<TheaterBO> GetTheaters(string searchtheater)
        {
            return MovieRepository.GetTheaters(searchtheater);
        }

        /// <summary>
        /// Gets the trailers.
        /// </summary>
        /// <returns>List{TrailerBO}.</returns>
        public static List<TrailerBO> GetTrailers()
        {
            return MovieRepository.GetTrailersMasterList();
        }

        #endregion
    }
}